#!/bin/bash
nginxurl=/opt/openresty/nginx
. $nginxurl/scripts/golo.conf
rc_name=$( cat /etc/rc.local |grep ALLstart|awk -F "." '{print $1}'|awk -F "/" '{print $6}')
if [ "$rc_name" == "ALLstart_M" ];then
        local_names="rtk" 
elif [ "$rc_name" == "ALLstart_M3" ];then
        local_names="rtkv3" 
elif  [ "$rc_name" == "ALLstartA_M" ];then
        local_names="aslam" 
else
        local_names='aslamv3' 
fi
if [ "$1" == "$local_names" ];then
        exit
fi
if [ -d "/home/nuc/.aslam_ws" ] && [ -d  "/home/nuc/.rtk_ws" ];then
case "$1" in
rtk|RTK)
	sudo sed -i 's/'"${rc_name}"'/ALLstart_M/g' /etc/rc.local;sudo echo "$1"> GOLO_WS_PATH/golo/websocket-client/scripts/data/aslam.txt;sleep 5;sudo reboot
       ;;
rtkv3|RTKV3)
	sudo sed -i 's/'"${rc_name}"'/ALLstart_M3/g' /etc/rc.local;sudo echo "$1"> GOLO_WS_PATH/golo/websocket-client/scripts/data/aslam.txt;sleep 5 ;sudo reboot
       ;;
aslam|ASLAM)
	 sudo sed -i 's/'"${rc_name}"'/ALLstartA_M/g' /etc/rc.local;sudo echo "$1"> GOLO_WS_PATH/golo/websocket-client/scripts/data/aslam.txt;sleep 5 ;sudo reboot
	;;
aslamv3|ASLAMV3)
	 sudo sed -i 's/'"${rc_name}"'/ALLstartA_M3/g' /etc/rc.local;sudo echo "$1"> GOLO_WS_PATH/golo/websocket-client/scripts/data/aslam.txt;sleep 5 ;sudo reboot
	;;
*)
	 exit ;
esac
else
exit
fi
